/*
 * @Author: xiangxiaojun
 * @Date: 2022-04-22 10:05:22
 * @Descripttion: 个人信息相关接口集
 */
import { getCookie, request } from '@inbiz/utils';
const version = InbizConfig.API_VERSION
// 根据token获取用户信息
export async function getUserInfoBytoken() {
  return request('/api/services/OrgV2User/GetUserInfoBytoken', {
    method: 'get',
    params: {
      token: getCookie('token'),
    },
  });
}

// 获取公司信息
export async function getAboutInfo() {
  return request('/api/services/SystemManagement/GetAboutInfo', {
    method: 'get',
    params: {
      token: getCookie('token'),
      lang: getCookie('lang'),
    },
  });
}

// 根据token获取用户头像
export function getUserAvatarBytoken(userId: any) {
  return `/ImageType/GetUserAvatar?token=${getCookie('token')}&userId=${userId}`;
}

// 获取登录/密码策略
export async function getLoginAndPasswordStrategy() {
  return request('/api/LoginVerification/GetLoginAndPasswordStrategy', {
    method: 'get',
    params: {
      token: getCookie('token'),
    },
  });
}

// 修改用户信息
export function editUser(params: any) {
  return request(`/WebCore`, {
    method: 'POST',
    data: {
      module: 'WebClient',
      fun: 'SaveUserInfo',
      ModifyPerDetails_txtRealname: params.realName,
      ModifyPerDetails_txtBirthday: params.birthday,
      ModifyPerDetails_chkGenderMale: params.genderMale,
      ModifyPerDetails_txtEmail: params.email,
      ModifyPerDetails_txtTelephone: params.telephone,
      ModifyPerDetails_txtMobile: params.mobile,
    },
    requestType: 'form',
  });
  // const token = getCookie('token');
  // return request(`/api/services/Org/SaveUserInfo?token=${token}`, {
  //   method: 'POST',
  //   data: {
  //     ...params,
  //     token: token,
  //   },
  // });
}

// 修改用户密码
export function changeUserPassword(params: any) {
  const token = getCookie('token');
  return request(`/api/services/OrgUser/ChangeUserPassword?token=${token}`, {
    method: 'POST',
    data: {
      oldPassword: params.oldPassword,
      newPassword: params.newPassword,
      token: token,
    },
  });
}

// 上传/更新用户头像
export function headUpload(params: any) {
  const token = getCookie('token');
  params.append('token', token);
  return request(`/ImageType/HeadUpload?token=${token}`, {
    method: 'POST',
    requestType: 'formData',
    body: params,
  });
}

// 上传/更新用户头像
export function mainImgPathUpload(params: any) {
  const token = getCookie('token');
  params.append('token', token);
  return request(`/ImageType/ImgCut?token=${token}`, {
    method: 'POST',
    requestType: 'formData',
    body: params,
  });
}

// 个性化配置
export function setUserConfig(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/userConfig/setUserConfig`, {
    method: 'POST',
    data: params,
  });
}

// 获取个人配置信息
export async function getUserConfig(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/userConfig/userConfig`, {
    method: 'get',
    params: {
      token: getCookie('token'),
      ...params,
    },
  });
}

// 注销登录
export function onSignOut() {
  return request(`/WebCore`, {
    method: 'POST',
    data: {
      module: 'OrgnizationManager',
      fun: 'UserLogout',
    },
    requestType: 'form',
  });
}

export async function userChooseTheme(params) {
  return request(`/inbiz/api/services/front/theme/v${version}/theme/setTheme`, {
    method: 'POST',
    params,
  });
}

export async function getCustomThemeDetail(params) {
  return request(`/inbiz/api/services/theme/v${version}/theme/content`, {
    params,
  });
}